package logic

import (
	"context"
	pb "zk1-project/proto/exam"
	"zk1-project/srv/internal/model/po"
)

// 定义空接口
type ExamInfoService struct {
	pb.UnimplementedExamServer
}

// 实现方法
func (s *ExamInfoService) ExamRegister(ctx context.Context, req *pb.ExamRegisterRequest) (resp *pb.ExamRegisterResponse, err error) {
	e := &po.Exam{
		Name:                req.Name,
		Sex:                 req.Sex,
		IdNumber:            req.IdNumber,
		RegistrationAddress: req.RegistrationAddress,
		RegistrationDate:    req.RegistrationDate,
		TestDate:            req.TestDate,
	}
	err = e.ExamRegister()
	if err != nil {
		return &pb.ExamRegisterResponse{
			Code: 400,
			Msg:  "考试报名失败",
		}, err
	}
	return &pb.ExamRegisterResponse{
		Code: 200,
		Msg:  "考试报名成功",
		Id:   int64(e.ID),
	}, nil
}
